package com.example;

import com.example.entity.Vehicle;
import com.example.entity.VehicleType;
import com.example.entity.VehicleStatus;
import com.example.repository.VehicleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class DataLoader implements CommandLineRunner {
    private final VehicleRepository vehicleRepository;

    @Autowired
    public DataLoader(VehicleRepository vehicleRepository) {
        this.vehicleRepository = vehicleRepository;
    }

    @Override
    public void run(String... args) throws Exception {
        if (vehicleRepository.count() == 0) {
            // 初始化测试车辆数据
            Vehicle vehicle = new Vehicle();
            vehicle.setLicensePlate("京A12345");
            vehicle.setModel("Toyota Camry");  // 补充 model 值
            vehicle.setSeats(4);
            vehicle.setType(VehicleType.ECONOMY);
            vehicle.setStatus(VehicleStatus.AVAILABLE);
            vehicleRepository.save(vehicle);
        }
    }
}